'''
Text多行文本框用于显示多行文本，还可以显示网页链接，图片，HTML页面
CSS样式，作为简单的文本处理器编辑器和网页浏览器来用
'''
from tkinter import *
import webbrowser

class Application(Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create()

    def create(self):
        self.w1 = Text(root, width=40, height=20, bg ="gray")
        self.w1.pack()

        self.w1.insert(1.0, "123456\n654321")
        self.w1.insert(2.0, "abcdef")

        Button(self, text="重复插入文本", command=self.insertText).pack(side=LEFT)
        Button(self, text="返回文本", command=self.returnText).pack(side=LEFT)
        Button(self, text="添加组件", command=self.addWidget).pack(side=LEFT)
        Button(self, text="访问百度", command=self.baidu).pack(side=LEFT)
    def insertText(self):
        self.w1.insert(INSERT, "123456")
        self.w1.insert(END,"654321")

    def returnText(self):
        print("所有文本：",self.w1.get(1.0,END))

    def addWidget(self):
        b1 = Button(self.w1, text="退出", command=root.destroy)
        self.w1.window_create(END, window=b1)

    def baidu(self):
        webbrowser.open("http://baidu.com")
root = Tk()
root.geometry("450x300+200+200")
app = Application(master=root)
app.mainloop()

